package com.csipsimple.ui;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;

import com.urnum.R;

public class WebLogOn extends Activity {
	private WebView webView;
	private Button okButton;
	private Button cancelButton;
	private Activity wl = this;
	
	
	public final static int RESULT_CONNECTION_OK = RESULT_FIRST_USER+1;
	public final static int RESULT_CANCEL = RESULT_FIRST_USER+2;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
        setContentView(R.layout.weblogon);

        // Create reference to UI elements
        webView  = (WebView) findViewById(R.id.webview_compontent);
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);

        
        
        
        okButton = (Button)findViewById(R.id.connection_ok);
        cancelButton = (Button)findViewById(R.id.cancel);
               
        // workaround so that the default browser doesn't take over
        webView.setWebViewClient(new MyWebViewClient());
        
        // Setup click listener
        okButton.setOnClickListener( new OnClickListener() {
        	public void onClick(View view1) {
        		wl.setResult(RESULT_CONNECTION_OK);
        		wl.finish();
        	}
        }); 
        
        cancelButton.setOnClickListener( new OnClickListener() {
        	public void onClick(View view2) {
        		wl.setResult(RESULT_CANCEL);
        		wl.finish();
        	}
        }); 
        
        openURL();
 
    }
    
    /** Opens the URL in a browser */
    private void openURL() {
    	webView.loadUrl("http://www.urnum.com");
    	//webView.requestFocus();
    }
    
    class MyWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    }    
}

